package com.obrempon.credit.market.ui.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.obrempon.credit.market.R
import com.obrempon.module.adapter.ObremponRecyclerViewAdapter
import com.obrempon.module.adapter.ObremponViewHolderHelper
import com.obrempon.module.shapeview.layout.ShapeConstraintLayout
import org.json.JSONObject

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2025/3/10 20:14
 * @Annotation：申请贷款 选择时间 item
 */
class ObremponApplyDayApt(recyclerView: RecyclerView?) : ObremponRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.obrempon_apply_day_item) {
    override fun setItemChildListener(helper: ObremponViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.dayItemLayout) //点击Item
    }
    override fun fillData(helper: ObremponViewHolderHelper, position: Int, model: JSONObject) {
        val textDays = helper.getTextView(R.id.textDays)
        textDays.text = model.optString("day")

        val dayItemLayout = helper.getView<ShapeConstraintLayout>(R.id.dayItemLayout)
        val imageDaysSelected = helper.getImageView(R.id.imageDaysSelected)

        if (model.optBoolean("isEnabled",true)){//可选
            if (model.optBoolean("isSelect",false)){
                dayItemLayout.shapeDrawableBuilder
                    .setSolidColor(getColor(R.color.color_ffd9e6ff))
                    .setStrokeColor(getColor(R.color.color_ff0569ff))
                    .setStrokeSize(4)
                    .intoBackground()
                textDays.setTextColor(getColor(R.color.color_ff0569ff))
                imageDaysSelected.visibility = View.VISIBLE
            } else {
                dayItemLayout.shapeDrawableBuilder
                    .setSolidColor(getColor(R.color.transparent))
                    .setStrokeColor(getColor(R.color.black))
                    .setStrokeSize(2)
                    .intoBackground()
                textDays.setTextColor(getColor(R.color.black))
                imageDaysSelected.visibility = View.GONE
            }
        } else {//不可选
            dayItemLayout.shapeDrawableBuilder
                .setSolidColor(getColor(R.color.color_ffe3e3e3))
                .setStrokeColor(getColor(R.color.color_ffe3e3e3))
                .intoBackground()
            textDays.setTextColor(getColor(R.color.white))
            imageDaysSelected.visibility = View.GONE
        }
    }
}